#include <cstdio>
#include <queue>
using namespace std;

priority_queue<int> q;

int main() {
	int n, a;
	char e;
	scanf("%d", &n);
	while (n--) {
		scanf("\n%c", &e);
		if (e == 'i') {
			scanf("%d", &a);
			q.push(-a);
		} else {
			printf("%d\n", -q.top());
			q.pop();
		}
	}
	return 0;
}
